
using System.Collections;
using System.Collections.Generic;


/// <summary>
/// 
/// </summary>
public class XEditorCoroutine : IEnumerator
{
    private Stack<IEnumerator> execStack;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="iterator"></param>
    public XEditorCoroutine(IEnumerator iterator)
    {
        execStack = new Stack<IEnumerator>();
        execStack.Push(iterator);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public bool MoveNext()
    {
        IEnumerator i = execStack.Peek();

        if (i.MoveNext())
        {
            object result = i.Current;
            if (result != null && result is IEnumerator)
            {
                execStack.Push((IEnumerator)result);
            }

            return true;
        }
        else
        {
            if (execStack.Count > 1)
            {
                execStack.Pop();
                return true;
            }
        }

        return false;
    }

    /// <summary>
    /// 
    /// </summary>
    public void Reset()
    {
        throw new System.NotSupportedException("This Operation Is Not Supported.");
    }

    /// <summary>
    /// 
    /// </summary>
    public object Current
    {
        get { return execStack.Peek().Current; }
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="iterator"></param>
    /// <returns></returns>
    public bool Find(IEnumerator iterator)
    {
        return execStack.Contains(iterator);
    }
}
